# !/usr/bin/env python3
import os,json,time
import sys, hashlib
from qiniu import Auth
from qiniu import BucketManager
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(BASE_DIR)


access_key = '224v7juZ_LTCGg227HAb8-sx6UZIXZtsqaU9KLh8'
secret_key = 'DxuxyFIDHO_TCbMvEqzkXeXRN-mnjXCflbWnLUWz'

#初始化Auth状态
q = Auth(access_key, secret_key)
#初始化BucketManager
bucket = BucketManager(q)

#获取资源信息
def get_detail(bucket_name, key):
    ret, info = bucket.stat(bucket_name, key)
    if ret == None:
        return True
    else:
        return False

#抓取网络资源到空间
def claw_net_resource(bucket_name, url):
    key = url.split('/')[-1]
    ret, info = bucket.fetch(url, bucket_name, key)
    print(ret)
    print(info)
    if ret == None:
        return True
    else:
        return False

if __name__=='__main__':
    # get_detail('prxiaoji', 'cover/img/2022-06-25/mixkit-100-dollar-bills-spinning-9357-small.jpg')
    claw_net_resource('prxiaoji', 'https://assets.mixkit.co/video-templates/preview/mixkit-large-title-slideshow-523-large.mp4')